﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Admin_AdminSendMessage_ManageMessage : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    public void PopulateMessage()
    {
        lvSendMessage.DataSource = ZNXX.GetAllByConditon(0, 0, txtTimeFrom.Text, txtTimeTo.Text, DongDong.Common.Misc.ConvertToInt(drpSFRead.SelectedValue), txtKey.Text, DongDong.Common.Misc.ConvertToInt(drpType.SelectedValue));
        lvSendMessage.DataBind();
    }
    public string ReturnZUserName(object UserID)
    {
        string UserName = "暂无信息";
        AdminUser objUserInfo = AdminUser.Get(DongDong.Common.Misc.ConvertToInt(UserID));
        if (objUserInfo != null)
        {
            UserName = objUserInfo.UserName;
        }
        return UserName;
    }
    public string ReturnUserName(object UserID, object TypeID)
    {
        string UserName = "暂无信息";
        if (DongDong.Common.Misc.ConvertToInt(TypeID) == (int)ZNXX.ZXXXType.后台)
        {
            AdminUser objUserInfo = AdminUser.Get(DongDong.Common.Misc.ConvertToInt(UserID));
            if (objUserInfo != null)
            {
                UserName = objUserInfo.UserName;
            }
        }
        if (DongDong.Common.Misc.ConvertToInt(TypeID) == (int)ZNXX.ZXXXType.前台)
        {
            Client objClient = Client.Get(DongDong.Common.Misc.ConvertToInt(UserID));
            if (objClient != null)
            {
                UserName = "<a target='_blank' href='../Client/Add.aspx?UserID=" + objClient.ID + "'>" + objClient.Username + "</a>";
            }
        }
        return UserName;
    }
    public string ReturnZT(object ZT)
    {
        string ZhuangTai = "";
        if ((int)ZT== (int)ZNXX.statusXX.未读)
        {
            ZhuangTai = "<span style='color:red'>" + "未读" + "</span>";
        }
        else
        {
            ZhuangTai = "已读";
        }
        return ZhuangTai;
    }
    protected void lvSendMessage_ItemDeleting(object sender, ListViewDeleteEventArgs e)
    {
        AdminUser objAdminUser = AdminUser.GetCurrent();
        if (objAdminUser != null)
        {
            int RoleID = objAdminUser.RoleID;
            AdminRole objAdminRole =AdminRole.Get(RoleID);
            if (objAdminRole != null)
            {
                string RoleName = objAdminRole.RoleName;
                if (RoleName == "超级管理员")
                {
                    int SendID = DongDong.Common.Misc.ConvertToInt(lvSendMessage.DataKeys[e.ItemIndex].Value);
                    ZNXX.BadDelete(SendID);
                    PopulateMessage();
                }
                else
                {
                    DongDong.Common.MessageBox.Show(this, "您不具有超级管理员权限!");
                }
            }
        }
    }
    protected void lvSendMessage_PagePropertiesChanged(object sender, EventArgs e)
    {
        PopulateMessage();
    }
    protected void Pager_PreRender(object sender, EventArgs e)
    {
        if (lvSendMessage.Items.Count == 0)
            PopulateMessage();
    }
    protected void btn_search_Click_Click(object sender, EventArgs e)
    {
        PopulateMessage();
    }
}